package com.jingan.nursinghome.regulatory.separate;

import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jingan.nursinghome.regulatory.MainActivity;
import com.jingan.nursinghome.regulatory.R;
import com.jingan.nursinghome.regulatory.data.MicrometerTable;
import com.jingan.nursinghome.regulatory.dialog.micrometertable.QianmiDialog;
import com.jingan.nursinghome.regulatory.dialog.micrometertable.XuantiDialog;
import com.jingan.nursinghome.regulatory.dialog.micrometertable.ZhangaiXiangDialog;
import com.jingan.nursinghome.regulatory.http.Http;
import com.jingan.nursinghome.regulatory.model.Topicinfo;
import com.jingan.nursinghome.regulatory.separate.bean.CreateMic;
import com.jingan.nursinghome.regulatory.view.BitmapsView;
import com.jingan.nursinghome.regulatory.view.MyActionBar;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.base.BasePhotoActivity;
import cn.android.support.v7.lib.sin.crown.base.BasePhotoListenner;
import cn.android.support.v7.lib.sin.crown.dialog.AlertDialog;
import cn.android.support.v7.lib.sin.crown.dialog.PhotoDialog;
import cn.android.support.v7.lib.sin.crown.dialog.ProgressDailog;
import cn.android.support.v7.lib.sin.crown.utils.AssetsUtils;
import cn.android.support.v7.lib.sin.crown.utils.NumberUtils;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;
import cn.android.support.v7.lib.sin.crown.utils.TimeUtils;
import cn.android.support.v7.lib.sin.crown.utils.ToastUtils;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

/**
 * 千分表提交界面
 * Created by 彭治铭 on 2017/10/19.
 */

public class SeparateCommitDailog extends BaseDialog {

    SeparateTableOSDialog micrometerTableOSDialog;

    public SeparateCommitDailog(BaseActivity baseActivity, SeparateTableOSDialog micrometerTableOSDialog) {
        init(baseActivity, R.layout.dialog_micrometertablleos_commit, false);
        window.setWindowAnimations(cn.android.support.v7.lib.sin.crown.R.style.crown_window_right);
        this.micrometerTableOSDialog = micrometerTableOSDialog;
        initUI();
        //adapterUI();
        initZ();
    }

    private void initZ() {
        TextView txt_zhengai = (TextView) findViewById(R.id.txt_zhengai);
        ProportionUtils.getInstance().adapterTextView(txt_zhengai);
        txt_zhengai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<Topicinfo> mTopics = new ArrayList<>();
                //当前题目里的整改项
                for (int i = 0; i < Uri.INSTANCE.getTopicinfoList().size(); i++) {
                    String zhengai = Uri.INSTANCE.getTopicinfoList().get(i).getZhengai().trim();
                    if (!zhengai.equals("0")) {
                        mTopics.add(Uri.INSTANCE.getTopicinfoList().get(i));
                    }
                }
//                历史整改里面的整改项
                for (int i = 0; i < Uri.INSTANCE.getTopicsHostoryQF().size(); i++) {
                    String zhengai = Uri.INSTANCE.getTopicsHostoryQF().get(i).getZhengai().trim();
                    if (!zhengai.equals("0")) {
                        mTopics.add(Uri.INSTANCE.getTopicsHostoryQF().get(i));
                    }
                }
                if (mTopics.size() > 0) {
                    ZhangaiXiangDialog.getInstance(baseActivity, mTopics, 0, new BaseListenner() {
                        @Override
                        public void onResult(Object result) {
                            SeparateTableOSDialog.micrometerTableOSDialog.updateAdapter();

                            int score = 0;//得分。
                            int maxScore = 0;//总分
                            //当前题目的得分和总分
                            for (int i = 0; i < Uri.INSTANCE.getTopicinfoList().size(); i++) {
                                Topicinfo topicinfo = Uri.INSTANCE.getTopicinfoList().get(i);
                                //Log.e("test","类型:\t"+topicinfo.getTopic_type());
                                if (topicinfo.getTopic_type() != null && topicinfo.getTopic_type().equals("2") || topicinfo.getTopic_score() == null) {
                                    continue;
                                }
                                maxScore = maxScore + Uri.INSTANCE.getTopicinfoList().get(i).getTopic_score();
                                String c = Uri.INSTANCE.getTopicinfoList().get(i).getPscore();
                                if (c != null && !c.trim().equals("")) {
                                    score = score + Integer.valueOf(c);
                                }
                            }
                            //历史整改的得分和总分
                            if (Uri.INSTANCE.getTopicsHostoryQF().size() > 0) {
                                for (int i = 0; i < Uri.INSTANCE.getTopicsHostoryQF().size(); i++) {
                                    Topicinfo topicinfo = Uri.INSTANCE.getTopicsHostoryQF().get(i);
                                    //Log.e("test","类型:\t"+topicinfo.getTopic_type());
                                    if (topicinfo.getTopic_type() != null && topicinfo.getTopic_type().equals("2") || topicinfo.getTopic_score() == null) {
                                        continue;
                                    }
                                    maxScore = maxScore + Integer.valueOf(Uri.INSTANCE.getTopicsHostoryQF().get(i).getTopic_score());
                                    String c = Uri.INSTANCE.getTopicsHostoryQF().get(i).getPscore();
                                    if (c != null && !c.trim().equals("")) {
                                        score = score + Integer.valueOf(c);
                                    }
                                }
                            }
                            mScore = score + "";
                            mMaxScore = maxScore + "";
                            txt_hdfs2.setText(mScore + "分/" + mMaxScore + "分");//得分
                            rate = NumberUtils.getInstance().getPercent(Integer.valueOf(mScore), Integer.valueOf(mMaxScore), 2);
                            txt_hdfs4.setText(rate);//得分率
                        }
                    });
                } else {
                    //ToastUtils.showToastView("暂无整改项");
                    baseActivity.SnackbarMake("暂无整改项", true, findViewById(R.id.dialog_micrometertableos_constraintLayout));
                }
            }
        });
    }

    private static SeparateCommitDailog commitDailog;

    static String mScore;//得分。
    static String mMaxScore;//总分

    static String spid;

    public static SeparateCommitDailog getInstance(BaseActivity baseActivity, SeparateTableOSDialog micrometerTableOSDialog, String maxScore, String score, String pid) {
        spid = pid;
        mScore = score;
        mMaxScore = maxScore;
        if (isfinish(baseActivity, commitDailog)) {
            commitDailog = new SeparateCommitDailog(baseActivity, micrometerTableOSDialog);
        }
        return commitDailog;
    }

    MyActionBar myActionBar;
    TextView txt_hostory, txt_select, txt_next;

    TextView txt_hdfs2;//得分
    TextView txt_hdfs4;//得分率
    TextView txt_xunjian;//巡检表类型
    TextView txt_jigou;//巡检机构
    TextView txt_time;//巡检时间
    TextView txt_goutou;//主要沟通人员
    EditText txt_beizhu2;//备注
    TextView txt_name;//套题名称

    Button btn_img;//上传照片
    Button btn_qianmi;//签名

    BitmapsView bitmapsView;//位图显示

    public void initUI() {
        myActionBar = (MyActionBar) findViewById(R.id.MyActionBar);
        myActionBar.setLeftBimapAndTitle(null, "评分结果");
        myActionBar.setBaseListennerLeft(new BaseListenner() {
            @Override
            public void onResult(Object result) {
                onBack();
            }
        });
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK
                        && event.getAction() == KeyEvent.ACTION_DOWN) {
                    onBack();
                    return true;//记得返回true。表示已经处理。
                }
                return false;//返回键以外交给系统自行处理。不可以屏蔽，不然输入法键盘的按键可能无效。如删除键
            }
        });
        txt_name = (TextView) findViewById(R.id.txt_name);
        txt_hostory = (TextView) findViewById(R.id.txt_hostory);
        txt_select = (TextView) findViewById(R.id.txt_select);
        txt_next = (TextView) findViewById(R.id.txt_next);
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.txt_hostory://上一项
                        dismiss();
                        break;
                    case R.id.txt_select://选题
                        XuantiDialog.getInstance(baseActivity, new BaseListenner<Integer>() {
                            @Override
                            public void onResult(Integer result) {
                                //返回当前页面
                                micrometerTableOSDialog.pageIndex = result;
                                //recyclerView.smoothScrollToPosition(pageIndex);
                                //linearLayoutManager.scrollToPosition(pageIndex);
                                micrometerTableOSDialog.linearLayoutManager.scrollToPositionWithOffset(micrometerTableOSDialog.pageIndex - 1, 0);
                                dismiss();
                            }
                        });
                        break;
                    case R.id.txt_next://提交
                        //fixme 虚假打分，模拟提交。========================================================================================================================================================================
//                        for (int i = 0; i < Uri.INSTANCE.getTopicinfoList().size(); i++) {
//                            Uri.INSTANCE.getTopicinfoList().get(i).setPscore("4");
//                            //Log.e("test", "分数:\t" + Uri.INSTANCE.getTopicinfoList().get(i).getCscore());
//                        }
//                        if (SeparateTableOSDialog.micrometerTableOSDialog.tihao.equals("") || true) {//true测试提交
                        if (SeparateTableOSDialog.micrometerTableOSDialog.tihao.equals("")) {
//                            if ((QMbitmap == null || QMbitmap.isRecycled()) && isZU) {//组长，才要签名
//                                baseActivity.SnackbarMake("签名不能为空!", true, findViewById(R.id.dialog_micrometertableos_constraintLayout));
//                                break;
//                            }
//                            if (isZU) {
//                                //组长 提交
//                                Map<String, String> map = new HashMap<>();
//                                Map<String, File> fileMap = new HashMap<>();
//                                if (isZU) {
//                                    File file = AssetsUtils.getInstance().saveBitmap(QMbitmap, baseActivity.getApplicationContext().getFilesDir().getAbsolutePath(), MicrometerTable.getInstance().getUser().getId() + CreateSeparateDailog.time + ".png");
//                                    //Log.e("test", "文件:\t" + file.getName() + "\t大小:\t" + file.length());
//                                    fileMap.put("signature", file);//签名,组长才要签名
//                                    map.put("pid", spid);
//                                    //多图片资源
//                                    for (int i = 0; i < files.size(); i++) {
//                                        if (i == 0) {
//                                            fileMap.put("polling_img_yi", files.get(i));
//                                        }
//                                        if (i == 1) {
//                                            fileMap.put("polling_img_er", files.get(i));
//                                        }
//                                        if (i == 2) {
//                                            fileMap.put("polling_img_san", files.get(i));
//                                        }
//                                        if (i == 3) {
//                                            fileMap.put("polling_img_si", files.get(i));
//                                        }
//                                        if (i == 4) {
//                                            fileMap.put("polling_img_wu", files.get(i));
//                                        }
//                                    }
//
//                                    //Log.e("test", "巡检人ID:\t" + Uri.INSTANCE.getUser().getId());
//                                    String t = TimeUtils.getInstance().getAbsoluteTime(" HH:mm:ss");
//                                    map.put("routing_inspection_time", CreateSeparateDailog.time + t);//巡检时间
//                                    map.put("oid", MicrometerTable.getInstance().getJlyID(CreateSeparateDailog.jlyName));//敬老院机构ID
//
//                                    //主要沟通人员ID
//                                    String[] lids = CreateSeparateDailog.names.split("、");
//                                    String lids2 = "";
//                                    for (int i = 0; i < lids.length; i++) {
//                                        String id = MicrometerTable.getInstance().getLinkupID(lids[i]);
//                                        if (i == 0) {
//                                            lids2 = id;
//                                        } else {
//                                            lids2 = lids2 + "," + id;
//                                        }
//                                    }
//                                    map.put("lid", lids2);//主要沟通人员id
//                                    map.put("remark", txt_beizhu2.getText().toString());//备注
//                                    map.put("otherpeople", CreateSeparateDailog.other);//其他
//                                    map.put("stname", CreateSeparateDailog.rid);//套题名称
//
//                                    Uri.INSTANCE.submitTup(activity, map, fileMap, new Function1<String, Unit>() {
//                                        @Override
//                                        public Unit invoke(String s) {
//                                            //提交
//                                            commit();
//                                            return null;
//                                        }
//                                    });
//                                }
//
//                            }
// else{
                            //组员 提交
                            commit();
//                            }
                        } else {
                            //还有题目没做完
                            baseActivity.SnackbarMake("未评分的题号如下:" + SeparateTableOSDialog.micrometerTableOSDialog.tihao, true, findViewById(R.id.dialog_micrometertableos_constraintLayout), new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    XuantiDialog.getInstance(baseActivity, new BaseListenner<Integer>() {
                                        @Override
                                        public void onResult(Integer result) {
                                            //返回当前页面
                                            micrometerTableOSDialog.pageIndex = result;
                                            //recyclerView.smoothScrollToPosition(pageIndex);
                                            //linearLayoutManager.scrollToPosition(pageIndex);
                                            micrometerTableOSDialog.linearLayoutManager.scrollToPositionWithOffset(micrometerTableOSDialog.pageIndex - 1, 0);
                                            dismiss();
                                        }
                                    });
                                }
                            });
                        }
                        break;
                }
            }
        };
        txt_hostory.setOnClickListener(onClickListener);
        txt_select.setOnClickListener(onClickListener);
        txt_next.setOnClickListener(onClickListener);

        txt_hdfs2 = (TextView) findViewById(R.id.txt_hdfs2);
        txt_hdfs4 = (TextView) findViewById(R.id.txt_hdfs4);
        txt_xunjian = (TextView) findViewById(R.id.txt_xunjian);
        txt_jigou = (TextView) findViewById(R.id.txt_jigou);
        txt_time = (TextView) findViewById(R.id.txt_time);
        txt_goutou = (TextView) findViewById(R.id.txt_goutou);
        txt_beizhu2 = (EditText) findViewById(R.id.txt_beizhu2);

        bitmapsView = (BitmapsView) findViewById(R.id.bitmaps);

        btn_img = (Button) findViewById(R.id.btn_img);
        btn_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //上传照片
                if (BasePhotoActivity.SnakbarView == null) {
                    BasePhotoActivity.SnakbarView = btn_img;
                }
                PhotoDialog.getInstance(MainActivity.mainActivity, true, new BasePhotoListenner() {
                    @Override
                    public void onSuccess(File file, Bitmap bitmap) {
                        if (bitmaps.size() < 5) {
                            bitmaps.add(bitmap);
                            files.add(file);
                        } else {
                            bitmaps.remove(4);
                            bitmaps.add(4, bitmap);
                            files.add(4, file);
                        }
                        bitmapsView.setBitmaps(bitmaps);
                    }
                });
            }
        });

        btn_qianmi = (Button) findViewById(R.id.btn_qianmi);
        btn_qianmi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //签名
                QianmiDialog.getInstance(baseActivity, new BaseListenner<Bitmap>() {
                    @Override
                    public void onResult(Bitmap result) {
                        QMbitmap = result;
                    }
                });
            }
        });

    }

    public static Bitmap QMbitmap;//签名位图

    public static List<Bitmap> bitmaps = new ArrayList<>();//位图数组
    public static List<File> files = new ArrayList<>();//位图文件数组

    public void adapterUI() {
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.dialog_micrometertableos_constraintLayout));
        ProportionUtils.getInstance().adapterTextView(txt_hostory);
        ProportionUtils.getInstance().adapterTextView(txt_select);
        ProportionUtils.getInstance().adapterTextView(txt_next);
        ProportionUtils.getInstance().adapterTextView((TextView) findViewById(R.id.txt_hdfs));
        ProportionUtils.getInstance().adapterTextView((TextView) findViewById(R.id.txt_beizhu));
        ProportionUtils.getInstance().adapterTextView((TextView) findViewById(R.id.txt_btn_img));
        ProportionUtils.getInstance().adapterTextView(txt_hdfs2);
        ProportionUtils.getInstance().adapterTextView(txt_xunjian);
        ProportionUtils.getInstance().adapterTextView(txt_jigou);
        ProportionUtils.getInstance().adapterTextView(txt_time);
        ProportionUtils.getInstance().adapterTextView(txt_goutou);
        ProportionUtils.getInstance().adapterTextView(txt_beizhu2);

        ProportionUtils.getInstance().adapterButton(btn_img);
        ProportionUtils.getInstance().adapterButton(btn_qianmi);

        ProportionUtils.getInstance().adapterTextView((TextView) findViewById(R.id.txt_hdfs3));
        ProportionUtils.getInstance().adapterTextView(txt_hdfs4);
        ProportionUtils.getInstance().adapterTextView(txt_name);
    }

    String rate = "";//得分率
    Boolean isZU = false;//是否为组长

    @Override
    protected void listener() {//FIXME ===================================================================================================================================================================================

        Uri.INSTANCE.putCache(spid);//缓存题目

        if (MicrometerTable.getInstance().getUser().getUtype().trim().equals("4")) {
            isZU = true;//组长
//            txt_beizhu2.setVisibility(View.VISIBLE);
//            btn_img.setVisibility(View.VISIBLE);
//            findViewById(R.id.txt_btn_img).setVisibility(View.VISIBLE);
//            btn_qianmi.setVisibility(View.VISIBLE);
//            findViewById(R.id.txt_beizhu).setVisibility(View.VISIBLE);

            txt_beizhu2.setVisibility(View.INVISIBLE);
            btn_img.setVisibility(View.INVISIBLE);
            findViewById(R.id.txt_btn_img).setVisibility(View.INVISIBLE);
            btn_qianmi.setVisibility(View.INVISIBLE);
            findViewById(R.id.txt_beizhu).setVisibility(View.INVISIBLE);

            txt_jigou.setText("巡检机构：" + CreateSeparateDailog.jlyName);
            txt_time.setText("巡检时间：" + CreateSeparateDailog.time);
            txt_goutou.setText("主要沟通人员:\t" + CreateSeparateDailog.names);
            txt_name.setText("套题名称:\t" + CreateSeparateDailog.rid);//套题名称

        } else {
            isZU = false;//组员
            txt_beizhu2.setVisibility(View.INVISIBLE);
            btn_img.setVisibility(View.INVISIBLE);
            findViewById(R.id.txt_btn_img).setVisibility(View.INVISIBLE);
            btn_qianmi.setVisibility(View.INVISIBLE);
            findViewById(R.id.txt_beizhu).setVisibility(View.INVISIBLE);

            Uri.INSTANCE.Fkpingfen(activity, spid, new BaseListenner<CreateMic>() {
                @Override
                public void onResult(CreateMic result) {

                    txt_jigou.setText("巡检机构：" + result.getOname());
                    txt_time.setText("巡检时间：" + result.getRouting_inspection_time());
                    txt_goutou.setText("主要沟通人员:\t" + result.getLname());
                    txt_name.setText("套题名称:\t" + result.getStname());//套题名称

                }
            });

        }
        txt_hdfs2.setText(mScore + "分/" + mMaxScore + "分");
        rate = NumberUtils.getInstance().getPercent(Integer.valueOf(mScore), Integer.valueOf(mMaxScore), 2);
        txt_hdfs4.setText(rate);
        txt_xunjian.setText("巡检表类型：千分表");

        bitmapsView.setBaseListener(new BaseListenner<Integer>() {
            @Override
            public void onResult(Integer result) {
                bitmaps.remove((int) result);
                files.remove((int) result);
                bitmapsView.setBitmaps(bitmaps);
            }
        });
        if (bitmaps.size() > 0) {
            bitmapsView.setBitmaps(bitmaps);
        }
    }

    AlertDialog alertDialog;

    void onBack() {
        alertDialog = AlertDialog.getInstance(baseActivity, false, false).setTitle("提示").setMession("是否退出本次评分?\n(我们将自动保存评分记录)");
        alertDialog.setPositive("是", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                micrometerTableOSDialog.dismiss();
                alertDialog.dismiss();
            }
        });
    }

    @Override
    protected void recycleView() {

    }

    public void commit() {
        ProgressDailog.buider(activity);//开启弹窗
        //题目
        Http.getInstance().UploadTimuImg(baseActivity, Uri.INSTANCE.getTopicinfoList(), new BaseListenner() {
            @Override
            public void onResult(Object result) {
                //历史整改题目
                Http.getInstance().UploadTimuImg(baseActivity, Uri.INSTANCE.getTopicsHostoryQF(), new BaseListenner() {
                    @Override
                    public void onResult(Object result) {
                        commit2();
                    }
                });
            }
        });
    }

    //提交
    public void commit2() {
        //提交
        Map<String, String> map = new HashMap<>();
        Map<String, File> fileMap = new HashMap<>();

//
//        //组长
//        if (isZU) {
//            File file = AssetsUtils.getInstance().saveBitmap(QMbitmap, baseActivity.getApplicationContext().getFilesDir().getAbsolutePath(), MicrometerTable.getInstance().getUser().getId() + CreateSeparateDailog.time + ".png");
//            //Log.e("test", "文件:\t" + file.getName() + "\t大小:\t" + file.length());
//            fileMap.put("signature", file);//签名,组长才要签名
//
//            //多图片资源
//            for (int i = 0; i < files.size(); i++) {
//                if (i == 0) {
//                    fileMap.put("polling_img_yi", files.get(i));
//                }
//                if (i == 1) {
//                    fileMap.put("polling_img_er", files.get(i));
//                }
//                if (i == 2) {
//                    fileMap.put("polling_img_san", files.get(i));
//                }
//                if (i == 3) {
//                    fileMap.put("polling_img_si", files.get(i));
//                }
//                if (i == 4) {
//                    fileMap.put("polling_img_wu", files.get(i));
//                }
//            }
//
//            //Log.e("test", "巡检人ID:\t" + Uri.INSTANCE.getUser().getId());
//            String t = TimeUtils.getInstance().getAbsoluteTime(" HH:mm:ss");
//            map.put("routing_inspection_time", CreateSeparateDailog.time + t);//巡检时间
//            map.put("oid", MicrometerTable.getInstance().getJlyID(CreateSeparateDailog.jlyName));//敬老院机构ID
//
//            //主要沟通人员ID
//            String[] lids = CreateSeparateDailog.names.split("、");
//            String lids2 = "";
//            for (int i = 0; i < lids.length; i++) {
//                String id = MicrometerTable.getInstance().getLinkupID(lids[i]);
//                if (i == 0) {
//                    lids2 = id;
//                } else {
//                    lids2 = lids2 + "," + id;
//                }
//            }
//            map.put("lid", lids2);//主要沟通人员id
//            map.put("remark", txt_beizhu2.getText().toString());//备注
//            map.put("otherpeople", CreateSeparateDailog.other);//其他
//            map.put("stname", CreateSeparateDailog.rid);//套题名称
//        }

        map.put("nameid", MicrometerTable.getInstance().getUser().getId());//巡检人ID
        JSONArray jsonArray2 = new JSONArray();
        try {
            int index = 0;
            //当前题目集合
            subject_list(Uri.INSTANCE.getTopicinfoList(), jsonArray2);
            //历史整改题目集合
            subject_list(Uri.INSTANCE.getTopicsHostoryQF(), jsonArray2);

        } catch (Exception e) {
            Log.e("test", "题目集合json异常:\t" + e.getMessage());
        }
//                            Log.e("test", "题目集合:\t\n" + jsonObject2.toString());
        map.put("subject_list", jsonArray2.toString());//巡检题目集合(参数为下面两个sid,sp_type请求参数)示例:如下
        map.put("rid", CreateSeparateDailog.rid);//题目类型
        map.put("total", mMaxScore);//总分
        map.put("scoring_rate", rate);//得分率
        map.put("pid", spid);
//        ProgressDailog.buider(activity);

//        Log.e("ui","pid:\t"+spid);
//        Log.e("ui","题目:\t"+jsonArray2);
        System.out.print(jsonArray2);
        Uri.INSTANCE.submit(map, fileMap, new Function1<String, Unit>() {
            @Override
            public Unit invoke(final String result) {

                if (micrometerTableOSDialog != null) {
                    micrometerTableOSDialog.dismiss();
                }
                ProgressDailog.tear(activity);//关闭弹窗
                //释放历史整改图片
                for (int i = 0; i < Uri.INSTANCE.getTopicsHostoryQF().size(); i++) {
                    for (int j = 0; j < Uri.INSTANCE.getTopicsHostoryQF().get(i).getBitmaps().size(); j++) {
                        if (Uri.INSTANCE.getTopicsHostoryQF().get(i).getBitmaps().get(j) != null && !Uri.INSTANCE.getTopicsHostoryQF().get(i).getBitmaps().get(j).isRecycled()) {
                            Uri.INSTANCE.getTopicsHostoryQF().get(i).getBitmaps().get(j).recycle();//清楚位图
                        }
                        Uri.INSTANCE.getTopicsHostoryQF().get(i).getBitmaps().clear();
                    }
                }
                //提交之后清空千分表历史整改记录。
                Uri.INSTANCE.getTopicsHostoryQF().clear();
                //释放题目图片
                for (int i = 0; i < Uri.INSTANCE.getTopicinfoList().size(); i++) {
                    for (int j = 0; j < Uri.INSTANCE.getTopicinfoList().get(i).getBitmaps().size(); j++) {
                        if (Uri.INSTANCE.getTopicinfoList().get(i).getBitmaps().get(j) != null && !Uri.INSTANCE.getTopicinfoList().get(i).getBitmaps().get(j).isRecycled()) {
                            Uri.INSTANCE.getTopicinfoList().get(i).getBitmaps().get(j).recycle();//清楚位图
                        }
                        Uri.INSTANCE.getTopicinfoList().get(i).getBitmaps().clear();
                    }
                }
                //提交之后，清除题目状态。
                Uri.INSTANCE.getTopicinfoList().clear();
                //清除画板
                QianmiDialog.clear();
                if (QMbitmap != null && !QMbitmap.isRecycled()) {
                    QMbitmap.recycle();
                }
                QMbitmap = null;

                if (files != null && files.size() > 0) {
                    files.clear();
                }

                //位图内存释放
                if (bitmaps != null) {
                    for (int i = 0; i < bitmaps.size(); i++) {
                        if (bitmaps.get(i) != null && !bitmaps.get(i).isRecycled()) {
                            bitmaps.get(i).recycle();
                        }
                    }
                    bitmaps.clear();
                    baseActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            bitmapsView.setBitmaps(bitmaps);
                        }
                    });
                }

                baseActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //Log.e("test","提示信息:\t"+result);
                        ToastUtils.showToastView(result);
                        dismiss();
                        micrometerTableOSDialog.dismiss();
                    }
                });

                return null;
            }
        });
    }

    private void subject_list(List<Topicinfo> topicinfos, JSONArray jsonArray2) {
        try {
            for (int i = 0; i < topicinfos.size(); i++) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("remark", topicinfos.get(i).getRemark());//备注
                jsonObject1.put("sid", topicinfos.get(i).getId());//题目ID
                jsonObject1.put("tid", topicinfos.get(i).getTid());//题号

                jsonObject1.put("topic_imgyi", topicinfos.get(i).getTopic_imgyi());//第一张图片
                jsonObject1.put("topic_imger", topicinfos.get(i).getTopic_imger());//第二张图片
                jsonObject1.put("topic_imgsan", topicinfos.get(i).getTopic_imgsan());//第三张图片
                Log.e("test", "josn图片:\t" + topicinfos.get(i).getTopic_imgyi() + "\t" + topicinfos.get(i).getTopic_imger() + "\t" + topicinfos.get(i).getTopic_imgsan() + "\t下标:\t" + i);

                //0无整改，1现场整改，2计划整改。
                jsonObject1.put("sp_type", topicinfos.get(i).getZhengai().trim());
                String topic_type = topicinfos.get(i).getTopic_type();
                if (topic_type == null) {
                    topic_type = "0";//空默认为0
                }
                String single_item_scor = topicinfos.get(i).getSingle_item_score();
                if (single_item_scor == null) {
                    single_item_scor = "";
                }
                jsonObject1.put("topic_type", topic_type);//题目类别(1为有小题类型	2为违法类型)
                if (topic_type.trim().equals("2")) {
                    jsonObject1.put("pscore", "0");//得分
                } else {
                    //Log.e("test","得分:\t"+topicinfos.get(i).getPscore());
                    if (topicinfos.get(i).getPscore() != null) {
                        jsonObject1.put("pscore", topicinfos.get(i).getPscore());//得分
                    } else {
                        jsonObject1.put("pscore", "0");//得分
                    }
                }
                jsonObject1.put("single_item_score", single_item_scor);//单体总分
                jsonArray2.put(jsonObject1);
                //Log.e("test", "题目集合:\t" + jsonObject1);
                //jsonArray2.put(i, jsonObject1);
                //Log.e("test","topic_type：\t"+Uri.INSTANCE.getTopicinfoList().get(i).getTopic_type()+"\tsingle_item_score:\t"+Uri.INSTANCE.getTopicinfoList().get(i).getSingle_item_score());
                //Log.e("test","题目ID:\t"+Uri.INSTANCE.getTopicinfoList().get(i).getId()+"\t整改:\t"+Uri.INSTANCE.getTopicinfoList().get(i).getZhengai().trim());
            }
        } catch (Exception e) {
            Log.e("test", "subject_list方法异常:\t" + e.getMessage());
        }
    }

}
